package cn.blog.mapper;

import cn.blog.entity.UserEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by mk on 2018/4/13/013.
 */
@Mapper
public interface UserMapper {
    @Select("SELECT * FROM tc_user")
    @Results({
            @Result(property = "userSex", column = "user_sex"),
            @Result(property = "nickName", column = "nick_name")
    })
    List<UserEntity> getAll();

    @Select("SELECT * FROM tc_user WHERE user_id = #{id}")
    @Results({@Result(property = "userSex", column = "user_sex"),
            @Result(property = "nickName", column = "nick_name")})
    UserEntity getOne(Long user_id);

    @Insert("INSERT INTO tc_user(user_name,password,user_sex,nick_name) VALUES(#{userName}, #{password}, #{userSex},#{nickName})")
    void insert(UserEntity user);

    @Update("UPDATE tc_user SET user_name=#{userName},nick_name=#{nickName} WHERE user_id =#{id}")
    void update(UserEntity user);

    @Delete("DELETE FROM tc_user WHERE user_id =#{id}")
    void delete(Long user_id);
}